﻿using DianDian.API.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace DianDian.API
{
    [DataContract]
    public abstract class APIResponse : BaseObject
    {
        private string body;
        /// <summary>
        /// 响应原始内容
        /// </summary>
        public string Body
        {
            get
            {
                return body;
            }
            set
            {
                //非调试状态下没必要存储
                if (System.Diagnostics.Debugger.IsAttached)
                    this.body = value;
            }
        }
        /// <summary>
        /// API返回数据状态
        /// </summary>
        [DataMember(Name = "meta")]
        public Meta MetaResponse
        {
            get;
            set;
        }
        //public string ErrorCode { get; set; }


        [DataMember(Name = "error_description")]
        public string ErrorDescription { get; set; }

        [DataMember(Name = "error")]
        public string Error { get; set; }

        public bool IsOK
        {
            get
            {
                if (MetaResponse.Msg == "OK")
                    return true;
                return false;
            }
        }
    }


    [DataContract]
    public class APIResponse<T> : APIResponse where T : BaseObject
    {


        [DataMember(Name = "response")]
        public ResponseData<T> Response
        {
            get;
            set;
        }


    }

    [DataContract]
    public class ResponseData<T> where T : BaseObject
    {
        [DataMember(Name = "posts")]
        public T[] Posts
        {
            get;
            set;
        }
    }
}
